#include <iostream>
#include <dll.h>

#include <stdio.h>
#include <QDebug>
#include <string>
#include <QTextCodec>
using namespace std;

int main(int argc, char* argv[])
{
//    printf("%s\n",argv[1]);

    QString label;
    string str;
    str = argv[1];
    label = QString::fromStdString(str);
//    qDebug()<<label;
    DLL* function = new DLL();

    function->OPENPORT("Gprinter GP-2120T");
    function->CLEARBUFFER();

    //  编程手册提到，如果有英文双引号，要进行如下的替换才能打印。所以这里做一步检查。
    //  " = \["]

    label.replace("\"","\\[\"]");

    //把utf-8编码转换为机器可以识别的GBK编码
    QTextCodec* utf8 = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForLocale(utf8);
    QTextCodec* gbk = QTextCodec::codecForName("gbk");
    QString strUnicode = utf8->toUnicode(label.toLocal8Bit().data());
    QByteArray gbk_bytes = gbk->fromUnicode(strUnicode);

    function->PRINTERFONT("25","120","TSS24.BF2","0","1","1",gbk_bytes.data());

    function->PRINTLABEL("1","1");
    function->CLOSEPORT();

    delete(function);
    return 0;
}

